import { _decorator, Component, Label, Node, Sprite } from 'cc';
import { GAME_POP, GAME_SPRITEFRAME, SOUND_TYPE } from '../Data/GlobalData';
import { HeadSkinInfo } from '../Data/GlobaInterface';
import { PopCollect } from './PopCollect';
const { ccclass, property } = _decorator;

@ccclass('PopBuy')
export class PopBuy extends Component {

    //篮球
    @property(Sprite)
    private Ball: Sprite = null;

    //金币数量
    @property(Label)
    private GoldNum: Label = null;

    //
    private MyIndex: number = 0;

    //篮球信息
    private BallSkinInfo: HeadSkinInfo = null;

    //皮肤场景
    public SkinBox: Node = null;

    /**
     * 更新样式
     */
    public UpdateStyle(_ballskininfo: HeadSkinInfo, _myindex: number) {
        this.BallSkinInfo = _ballskininfo;
        this.MyIndex = _myindex;
        this.Ball.spriteFrame = app.resManager.SpriteFrames[GAME_SPRITEFRAME.DragonHead + (_ballskininfo.Index)];
        this.GoldNum.string = _ballskininfo.Price.toString();
    }

    /**
     * 点击确定按钮
     */
    private ConfirmClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.gameData.GameData.coin -= this.BallSkinInfo.Price;
        app.gameData.GameData.basket = this.MyIndex;
        app.gameData.UpdateGameDateLocal();
        this.SkinBox.getComponent(PopCollect).UpdateLocalStorage(this.MyIndex);
        app.topManager.HideTop(GAME_POP.PopBuy);

    }

    /**
     * 点击取消按钮
     */
    private CannelClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.topManager.HideTop(GAME_POP.PopBuy);

    }

}


